import api from '@/api';
import { utils } from 'hash.js';
import Pagetion from '../utils/Pagetion'

export default {
  namespace:'cooperativeStore',
  state: {
    list:[],
    BasicInfoId:'',
    refrenshList:[],// 查询用的数组
    RoleByUserId:[],// 角色数组
  },
  effects:{
    *queryList({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.queryList, payload);
        return res;
      },
      *queryBasicInfo({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.queryBasicInfo, payload);
        return res;
      },
      *queryPriceBreakdown({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.queryPriceBreakdown, payload);
        return res;
      },
      *queryShopSign({ payload }, { call }) {//合作店铺-列表接口
        const res= yield call(api.cooperativeStore.queryShopSign, payload);
        return res;
      },
      *updateShopApplyPrice({ payload }, { call }) {//更新合作申请价格(合作申请)
        const res= yield call(api.cooperativeStore.updateShopApplyPrice, payload);
        return res;
      },
      *querySysUser({ payload }, { call,put }) {//账号管理-新建账号列表查询
        const res= yield call(api.cooperativeStore.querySysUser, payload);
        if(res.code==200){
          yield put({
            type:'refrensh',
            payload: res.data.querySysUserDto.resultList
          });
        }
        return res;
      },
      *addSysUser({ payload }, { call }) {//账号管理-新建系统用户
        const res= yield call(api.cooperativeStore.addSysUser, payload);
        return res;
      }, //账号管理-新建账号-添加人员（根据用户id查询用户下所有角色）
      *querySysRoleByUserId({ payload }, { call,put }) {
        const res= yield call(api.cooperativeStore.querySysRoleByUserId, payload);
        if(res.code==200){
          yield put({
            type:'queSysRoleByUserId',
            payload: res.data
          });
        }
        return res;
      }, // 账号管理- 更新用户基本信息
      *updateUserBasicInfo({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.updateUserBasicInfo, payload);
        return res;
      },
      *updateUserBasicInfoStatus({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.updateUserBasicInfoStatus, payload);
        return res;
      },


      *spsWareHouseInsert({ payload }, { call }) {//新建仓库信息(仓库管理)
        const res= yield call(api.cooperativeStore.spsWareHouseInsert, payload);
        return res;
      },
      //我的信息-仓库管理-查询
      *spsSelectWareHouse({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.spsSelectWareHouse, payload);
        return res;
      },//我的信息-仓库管理-修改
      *spsWareHouseUpdate({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.spsWareHouseUpdate, payload);
        return res;
      }, //我的信息-仓库管理-删除
      *spsWareHouseDelete({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.spsWareHouseDelete, payload);
        return res;
      },
      //仓库管理-查询一级货物类型
      *selectOneLevel({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.selectOneLevel, payload);
        return res;
      },
      //仓库管理-货物类型-根据parent_code搜索货物类型
      *selectByParentCode({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.selectByParentCode, payload);
        console.log("货物类型:",res)
        return res;
      },
      // 搜素国家
      *findAllCountry({ payload }, { call }) {
        const res= yield call(api.cooperativeStore.findAllCountry, payload);
        console.log("查询所有国家:",res)
        return res;
      },
      // 获取所有货物类型
      *getAllCode({ payload }, { call }) {
        return yield call(api.cooperativeStore.getAllCode, payload)
      },
  },
  reducers: {
    refrensh(state,{payload}){
      console.log('payload',payload);
      return{
        ...state,
        refrenshList: payload,
      };
    },
    queSysRoleByUserId(state,{payload}){
      console.log('payload---角色数组',payload);
      return{
        ...state,
        RoleByUserId:payload
      }
    }

  }
}